<?php

class indexActions extends sfActions
{
	public function executeIndex(sfWebRequest $request) {
		$con = Propel::getConnection();
		
		$query = 'SELECT SUM('.ExpensePeer::AMOUNT.') AS amount FROM '.ExpensePeer::TABLE_NAME;
		$stmt = $con->prepare($query);
		$stmt->execute();
		$result = $stmt->fetch();
		$this->amount = $result['amount'];
		
		$query = 'SELECT SUM('.ExpensePeer::AMOUNT.') AS amount FROM '.ExpensePeer::TABLE_NAME.
						' JOIN '.ExpenseTagPeer::TABLE_NAME.' ON '.ExpenseTagPeer::EXPENSE_ID.'='.ExpensePeer::ID.
						' JOIN '.TagPeer::TABLE_NAME.' ON '.ExpenseTagPeer::TAG_ID.'='.TagPeer::ID.
						' WHERE '.TagPeer::NAME.' = "Первая необходимость"';
		$stmt = $con->prepare($query);
		$stmt->execute();
		$result = $stmt->fetch();
		$this->necessityAmount = $result['amount'];
		
		$query = 'SELECT '.ExpensePeer::CREATED_AT.' FROM '.ExpensePeer::TABLE_NAME.' ORDER BY '.ExpensePeer::CREATED_AT.' ASC LIMIT 1';
		$stmt = $con->prepare($query);
		$stmt->execute();
		$result = $stmt->fetch();
		$this->firstCreatedAt = strtotime($result['CREATED_AT']);
		$this->days = (int)((time() - $this->firstCreatedAt)/(60*60*24));
		
		
	}

}
